#6-1
student_list = [("name","xiaoqian"),("stu_id","202201"),("grade","second")]
student_dict = dict(student_list)
print(student_dict)

#6-2
student_dict = dict(name="xiaoqian",stu_id="202201",grade="second")
print(student_dict)

#6-3
student_dict={"name":"xiaoqian","stu_id":"202201","grade":"second"}
print("xuehao:",student_dict["stu_id"])

#student_dict={"name":"xiaoqian","stu_id":"202201","grade":"second"}
#print("xuehao:",student_dict["score"])

#6-4
student_dict={"name":"xiaoqian","stu_id":"202201","grade":"second"}
score_value = student_dict.get("score","no existent")
print(score_value)

#6-5
C_dict ={
    "xiaoqian":"Leo",
    "xiaofeng":"Taurus",
    "xiaohe":"Taurus",
    "xiaoding":"Virgo",
}
for item in C_dict.items():
    print(item)

#6-6
C_dict = {
    "xiaoqian":"Leo",
    "xiaofeng":"Taurus",
    "xiaohe":"Taurus",
    "xiaoding":"Virgo",
    }
for key,value in C_dict.items():
    print(f"{key}dexingzuoshi{value}")

#6-7
C_dict = {
    "xiaoqian":"Leo",
    "xiaofeng":"Taurus",
    "xiaohe":"Taurus",
    "xiaoding":"Virgo",
    }
for name in C_dict.keys():
    print(name)

#6-8
C_dict = {
    "xiaoqian":"Leo",
    "xiaofeng":"Taurus",
    "xiaohe":"Taurus",
    "xiaoding":"Virgo",
    }
if "zhangsan" not in C_dict.keys():
    print("zhangsan not attend meeting!")

#6-9
C_dict = {
    "xiaoqian":"Leo",
    "xiaofeng":"Taurus",
    "xiaohe":"Taurus",
    "xiaoding":"Virgo",
    }
for cons in C_dict.values():
    print(cons)

#6-10
C_dict = {
    "xiaoqian":"Leo",
    "xiaofeng":"Taurus",
    "xiaohe":"Taurus",
    "xiaoding":"Virgo",
    }
for cons in set(C_dict.values()):
    print(cons)

#6-11
student_dict = dict(name="xiaoqian",stu_id="202201",grade="second")
if "name" in student_dict:
    print("zidianzhonghanyou'name'jian")
else:
    print("zidianzhongmeiyou'anme'jian")

#6-12
person_dict = {"name":"xioaqian","age":20}
person_dict["name"] = "xiaofeng"
print(person_dict)

#6-13
person_dict = {"name":"xioaqian","age":20}
person_dict["grade"] = "second"
print(person_dict)

#6-14
person_dict = {"name":"xiaoqian","age":20}
value = person_dict.setdefault("name","xiaofeng")
print(f"back:{value},dictionary:{person_dict}")

#6-15
person_dict = {{"name":"xiaoqian","age":20}}
del person_dict["age"]
print(person_dict)

goods_dict = {
	"milk":20,
	"cup":10,
	"potatochips":20,
}
laster_goods = goods_dict.copy()
laster_goods["milk"] += 10
print("yuanhuojiaxinxi:",goods_dict)
print("xianhuojiaxinxi:",laster_goods)


dict01 = {"a":1,"b":2}
dict02 = {"a":3,"d":4}
dict01.updata(dict02)
print(dict01)

dict01 = {"a":1,"b":2}
dict02 = {"a":3,"d":4}
dict03 = {**dict01,**dict02}
print(dict03)

dict01 = {"a":1,"b":2}
dict02 = {"a":3,"d":4}
dict03 = dict01|dict02
print(dict03)

dict01 = {"a":1,"b":2}
dict02 = {"a":3,"d":4}
dict01 |= dict02
print(dict01)

square_dict = {}
for i in range(1,6):
	square_dict[i] = i**2
print(square_dict)

person_list = [("xiaoqian",20),("xiaofeng",19),("xiaokou",17),("xiaoding",18)]
teenager_dict = {}
for name,age in person_list:
	if age < 18:
		teenager_dict[name] = age
print(teenager_dict)


person_list = [("xiaoqian",20),("xiaofeng",19),("xiaokou",17),("xiaoding",18)]
teeager_dict = {name:age for name,age in person_list if age < 18}
print(teenager_dict)

waste_dict = {
	"kehuishoulaji":["boli","jinshu","suliaodai","zhizhang","yifu"],
	"ganlaji":["canjinzhi","suliaodai","zhijin","zhiniaoku","huapen","taoci"],
	"shilaji":["shenfanshencai","huapiguohe","huahuilvzhi","guoqishipin"],
	"youhailaji":["dianchi","youqitong","yingguangdengguan","feiyaopin"],
}

while True:
	search_waste = input("lajizhonglei:")
	find = False
	if search_waste == "q":
		break
	for classify,waste in waste_dict.items():
		if search_waste in waste:
			find = True
			print(f"{search_waste}deleibieshi{classify}")
			print("-"*30)
	if find == False:
		print("meiyouzhaodaogailajifenlei,qingzixingpanduan")
		print("-"*30)
		for classify,waste in waste_dict.items():
			print(f"{classify}baokuo:",end="")
			for item in waste:
				if waste.index(item) == len(waste) - 1:
					print(item)
				else:
					print(item,end=", ")
			print("-" * 30)
			break
		
while True:
	option = input("nishifouxiwangjiangcilajijiaruxianyoufenlei(yes/no)?")
	if option == "yes":
		classify = input("nixiwangjiangcilajijiarunagefenleibie?")
		try:waste_dict[classify].append(search_waste) 
		except KeyError:
			print("nideshuruyouwu,meiyoucileibie")
		break
	elif option == "no":
		print("keyijixuchaxunlajifenlei")	
		break
	else:
		print("nideshuruyouwu,qingchongxinshuru")
-----------------------------------------------------------------------------------------------------
下载jieba

		
import jieba
cut_list = jieba.lcut("weizhonghuazhijueqierdushu")
print(cut_list)


from jieba import *
sentence = "tongyixingshimaodunshuangfangxianghuyicun,xianghuguantongdexingzhihequshi"
list01 = lcut(sentence)
list02 = lcut(sentence,cut_all = True)
list03 = lcut_for_search(sentence)
print(f"jingquemoshifencijieguo{list01}")
print(f"quanmoshifencijieguo{list02}")
print(f"sousuoyinqinmoshifencijieguo{list03}")

import jieba
sentence = "qianfengjiaoyuyizhibingchi'yongliangxinzuojiaoyu'delinian"
word_list = jieba.lcut(sentence)
print(word_list)

import jieba
sentence = "qianfengjiaoyuyizhibingchi'yongliangxinzuojiaoyu'delinian"
jieba.add_word("qianfengjiaoyu")
word_list = jieba.lcut(sentence)
print(word_list)

import jieba
sentence = "qianfengjiaoyuyizhibingchi'yongliangxinzuojiaoyu'delinian"
jieba.del_word("linian")
word_list = jieba.lcut(sentence)
print(word_list)

import jieba.analyse
a_text = """
aaaaaaaaaabbbbbbbbbbccccccccccccc
"""
keywords = jieba.analyse.extract_tags(a_text,topK=5)
print(keywords)

import jieba
with open("comment,txt","r",encoding="utf-8") as f:
	text = f.read()
comment_words = jieba.lcut(text)
comment_dict = {}
for word in comment_words:
	if len(word) == 1:
		continue
	else:
		comment_dict[word] = comment_dict.get(word,0) + 1
sort_list = sorted(comment_dict.items(),key=lambda x:x[1],reverse=True)
for i in range(15):
	word,count = sort_list[i]
	print(f"{word:^10}{count:^10}")
	
import jieba
result = jieba.luct("bad")
print(result)

import jieba
jieba.add_word("bad")
result = jieba.lcut("bad")
print(result)

import jieba
text = open("commment.txt","r",encoding="utf-8").read()
jieba.add_word("bad")
jieba.add_word("not")
jieba.add_word("nolike")
comment_words = jieba.lcut(text)
comment_dict = {}
for wod in comment_words:
	if len(word) == 1:
		continue
	else:
		comment_dict[word] = comment_dict.get(word,0) + 1
	sort_list = sorted(comment_dict.items(),key=lambda x:x[1],reverse=True)
	for i in range(15):
		word,count = sort_list[i]
	print(f"{word:^10}{count:^10}")
	
dict01 = {}
print("{}leixing:",type(dict01))
set01 = {"xiaoqian","xiaofeng"}
print("set01leixingshi",type(set01))

set01 = {"xiaoqian","xiaofeng","xiaoqian"}
print(set01)

set01 = set("qianfeng")
set02 = set(("xiaoqian","xiaofeng"))
set03 = set(["xiaoqian","xiaofeng"])
set04 = set({"xiaoqian":19,"xiaofeng":18})
print("set01:",set01)
print("set02:",set02)
print("set03:",set03)
print("set04:",set04)

language_set = {"chinese","english","french"}
language_set.add("russian")
print(language_set)

language_set= {"chinese","english","french"}
language_set.discard("english")
print(language_set)
language_set.remove("french")
print(language_set)

set01 = {1,2,3,4}
set02 = {2,3,4,5}
print("set01&set02:",set01&set02)
print("set01|set02:",set01|set02)
print("set01-set02:",set01-set02)
print("set01^set02:",set01^set02)